home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / totdoc.zip / CHAPT14.TXT < prev    next >
Text File  |  1991-02-11  |  29KB  |  757 lines

  1.                                                                           String
  2.                                                                         Handling
  3.  
  4.  
  5.  
  6.          "Guests, like fish, begin to smell after three days."
  7.  
  8.                                                                Benjamin Franklin
  9.  
  10.  
  11.  
  12.          The totSTR unit provides a set of routines for converting data to and
  13.          from string format. Although the unit includes the object FmtNumberOBJ,
  14.          the majority of the routines are good ol' functions.
  15.  
  16.  
  17. String Functions
  18.  
  19.          These functions are grouped into the following categories reflecting
  20.          their primary purpose: string adjustment, string searching, word man-
  21.          agement and number conversion.
  22.  
  23.  
  24. String Adjustment
  25. Squeeze
  26.  
  27.          Squeeze(L:char;Str:string;Width:byte);
  28.          Returns a string that has been squeezed (or expanded) to a specific
  29.          length. If the source string is too long, either the leftmost or right-
  30.          most characters are removed. The function is passed three parameters; a
  31.          character to indicate which side of the string to truncate ('L' or
  32.          'R'), the source string, and the desired string width. If the source
  33.          string is shorter than the desired width, the string is padded with
  34.          spaces. For example:
  35.  
  36.                   TIGHT :=SQUEEZE('L','ARKANSAS',6);
  37.          Assigns the value 'KANSAS' to TIGHT.
  38.  
  39.  
  40.  
  41. PadLeft
  42.          Padleft(Str:string;Size:byte;ChPad:char):string;
  43.  
  44.          Expands and left justifies a string to a specified width. The function
  45.          is passed three parameters; the source string, the length of the
  46.          expanded string, and the character used to pad the string. For example:
  47.                   MyString := PadLeft('LOAD FILE',20,' ');
  48.  
  49.          Assigns the value 'LOAD FILE          ' to MyString.
  50.  
  51. 14-2                                                                User's Guide
  52. --------------------------------------------------------------------------------
  53.  
  54. PadRight
  55.  
  56.          PadRight(Str:string;Size:byte;ChPad:char):string;
  57.          Expands and right justifies a string to a specified width. The function
  58.          is passed three parameters; the source string, the length of the
  59.          expanded string, and the character used to pad the string. For example:
  60.  
  61.                   MyString := PadRight('RIGHT',10,'*');
  62.          Assigns the value '*****RIGHT' to MyString.
  63.  
  64.  
  65.  
  66. PadCenter
  67.          PadCenter(Str:string;Size:byte;ChPad:char):string;
  68.  
  69.          Expands and centers a string to a specified width. The function is
  70.          passed three parameters; the source string, the length of the expanded
  71.          string, and the character used to pad the string. For example:
  72.                   Bored := PadCenter('Middle',14,'-');
  73.  
  74.          Assigns the value '----Middle----' to Bored.
  75.  
  76.  
  77. Pad
  78.  
  79.          Pad(PadJust:tJust;Str:string;Size:byte;ChPad:char):string;
  80.          This function combines the features of PadLeft, PadRight and PadCenter
  81.          into a single function. The totSTR unit includes the declaration of an
  82.          enumerated type tJust, with the following members: JustLeft, Just-
  83.          Center, and JustRight. The function is passed four parameters; a member
  84.          of tJust to indicate the required justification, the source string, the
  85.          length of the expanded string, and the character used to pad the
  86.          string. For example:
  87.  
  88.                   PadStr := Pad(JustCenter,'Middle',14,'-');
  89.          Assigns the value '----Middle----' to PadStr.
  90.  
  91.  
  92.  
  93. SetUpper
  94.          SetUpper(Str:string):string;
  95.  
  96.          Returns a string with all the alpha characters converted to upper case.
  97.          The string is passed one parameter; the source string. For example:
  98.                   MyString := SetUpper('123abc456dEf');
  99.  
  100.          Assigns the value '123ABC456DEF' to MyString.
  101.  
  102. String Handling                                                             14-3
  103. --------------------------------------------------------------------------------
  104.  
  105. SetLower
  106.  
  107.          SetLower(Str:string):string;
  108.          Returns a string with the alpha characters converted to lower case. The
  109.          string is passed one parameter; the source string. For example:
  110.  
  111.                   MyString := SetLower('123ABC456DeF');
  112.          Assigns the value '123abc456def' to MyString.
  113.  
  114.  
  115.  
  116. SetProper
  117.          SetProper(Str:string):string;
  118.  
  119.          Returns a string with the first character of each word converted to
  120.          upper case. The string is passed one parameter; the source string. For
  121.          example:
  122.                   MyString := SetProper('eeny meeny miny mo');
  123.  
  124.          Assigns the value 'Eeny Meeny Miny Mo' to MyString.
  125.  
  126.  
  127. AdjCase
  128.  
  129.          AdjCase(NewCase:tCase; Str:string): string;
  130.          This function combines the features of SetUpper, SetLower and SetProper
  131.          into a single function. The totSTR unit includes the declaration of an
  132.          enumerated type tCase, with the following members: Lower, Upper,
  133.          Proper, and Leave. If the member Leave is specified, the string will
  134.          not be adjusted. The function is passed two parameters; a member of
  135.          tCase to indicate the required capitalization, and the source string.
  136.          For example:
  137.  
  138.                   PStr := AdjCase(Proper,'tracy chapman');
  139.          Assigns the value 'Tracy Chapman' to PStr.
  140.  
  141.  
  142.  
  143. Last
  144.          Last(N:byte; Str:string):string;
  145.  
  146.          Returns the last part of a string. The function is passed two parame-
  147.          ters; the number of characters to extract, and the source string. For
  148.          example:
  149.                   NewString := Last(11,'Never take drugs!');
  150.  
  151.          Assigns the value 'take drugs!' to NewString.
  152.  
  153. 14-4                                                                User's Guide
  154. --------------------------------------------------------------------------------
  155.  
  156. First
  157.  
  158.          First(N:byte; Str:string):string;
  159.          Returns the first part of a string. The function is passed two parame-
  160.          ters; the number of characters to extract, and the source string. For
  161.          example:
  162.  
  163.                   MyString := First(10,'I want sextuplets');
  164.          Assigns the value 'I want sex' to MyString.
  165.  
  166.  
  167.  
  168. Strip
  169.          Strip(L,C:char; Str:string): string;
  170.  
  171.          Returns the string with a specific character removed. The function is
  172.          passed three parameters; a character to indicate which part of the
  173.          string to strip, the character to strip, and the source string. The
  174.          strip can be performed on the left of the string, the right of the
  175.          string, the left and right, or all occurrences throughout the string.
  176.          The first parameter would be the character 'L', 'R', 'B' or 'A',
  177.          respectively. For example:
  178.                   NoTees := Strip('A','T','THE TTT MAN');
  179.  
  180.          Assigns the value 'HE  MAN' to NoTees.
  181.  
  182.  
  183. OverType
  184.  
  185.          OverType(N:byte; StrS,StrT:string):string;
  186.          Places one string "on top of" another string and overlays the underly-
  187.          ing characters. The function is passed three parameters; the character
  188.          position in the target string to start the overtyping, the source
  189.          string, and the target string. For example:
  190.  
  191.                   Result := Overtype(8,'TechnoJock','I love you');
  192.          Assigns the value 'I love TechnoJock' to Result.
  193.  
  194.  
  195.  
  196. PicFormat
  197.          PicFormat(Input,Picture:string;Pad:char):string;
  198.  
  199.          This function was specifically used to complement the PictureIOOBJ
  200.          object used for obtaining formatted user input. The function returns a
  201.          formatted string, and is passed three parameters; the source string,
  202.          the picture string containing the format characters '!@*#', and the
  203.  
  204.  
  205. String Handling                                                             14-5
  206. --------------------------------------------------------------------------------
  207.  
  208.          character used to pad the string if the source is not long enough.
  209.          Refer to chapter 11 for a full description of format characters. For
  210.          example:
  211.  
  212.                   TelStr := PicFormat('713493635','(###) ###-####','*');
  213.          Assigns the value '(713) 493-635*' to TelStr.
  214.  
  215.  
  216.  
  217. TruncFormat
  218.          TruncFormat(Input:string; Start,Len:byte; Pad:char):string;
  219.  
  220.          Truncates (or expands) a string from a specified character position.
  221.          The function is passed three parameters; the source string, the posi-
  222.          tion of the first character to extract, and the total length of the
  223.          returned string. For example:
  224.                   NewStr := TruncFormat('Hidey Hidey Ho',9,10);
  225.  
  226.          Assigns the value 'dey Ho    ' to NewStr.
  227.  
  228.  
  229. String Searching
  230.  
  231. FirstCapital
  232.          FirstCapital(Str:string):char;
  233.  
  234.          Returns the first capital letter in a string. Note that this function
  235.          returns type char. If a capital letter is not found, a null (#0) is
  236.          returned. The function is passed one parameter; the source string. For
  237.          example:
  238.                   MyChar := FirstCapital('7 File Save');
  239.  
  240.          Assigns the value 'F' to MyChar.
  241.  
  242.  
  243. FirstCapitalPos
  244.  
  245.          FirstCapitalPos(Str:string):byte;
  246.          Returns the character position of the first capital letter in a string.
  247.          Note that this function returns type byte. If a capital letter is not
  248.          found, a zero is returned. The function is passed one parameter; the
  249.          source string. For example:
  250.  
  251.                   ByteVar := FirstCapitalPos('how yer doin Bob');
  252.          Assigns the value 14 to ByteVar.
  253.  
  254.  
  255.  
  256. 14-6                                                                User's Guide
  257. --------------------------------------------------------------------------------
  258.  
  259. LastPos
  260.  
  261.          LastPos(C:char;Str:string):byte;
  262.          Returns a byte indicating the position of the last occurrence of a
  263.          character in a string. If the character is not found, a zero is
  264.          returned. The function is passed two parameters; a character to search
  265.          for, and the source string. For example:
  266.  
  267.                   BytePos := LastPos('A','My Accommodation');
  268.          Assigns the value 4 to BytePos.
  269.  
  270.  
  271.  
  272. LastPosBefore
  273.          LastPosBefore(C:char;Str:string;Last:byte): byte;
  274.  
  275.          Returns a byte indicating the position of the last occurrence of a
  276.          character, up to a specified part of the string. If the character is
  277.          not found, a zero is returned. The function is passed three parameters;
  278.          a character to search for, the source string, and the position of the
  279.          last character to include in the search. For example:
  280.                   SubPos := LastPosBefore('s','Mississippi',5);
  281.  
  282.          Assigns the value 4 to SubPos.
  283.  
  284.  
  285. PosAfter
  286.  
  287.          PosAfter(C:char;Str:string;Start:byte):string;
  288.          Returns a byte indicating the position of the first occurrence of a
  289.          character, starting from a specified position in the string. If the
  290.          character is not found, a zero is returned. The function is passed
  291.          three parameters; a character to search for, the source string, and the
  292.          position of the first character to include in the search. For example:
  293.  
  294.                   SubPos := PosAfter('s','Mississippi',5);
  295.          Assigns the value 6 to SubPos.
  296.  
  297.  
  298. Word Management
  299. WordCnt
  300.  
  301.          WordCnt(Str:string):byte;
  302.          Returns the number of words in a string. The procedure is passed one
  303.          parameter; the source string. For example:
  304.  
  305.                   TotWords := WordCnt('eeny meeny miny mo');
  306.  
  307. String Handling                                                             14-7
  308. --------------------------------------------------------------------------------
  309.  
  310.          Assigns the value 4 to TotWords.
  311.  
  312.  
  313.  
  314. PosWord
  315.          PosWord(WordNo:byte; Str:string):byte;
  316.  
  317.          Returns the position of the first character of a specific word in a
  318.          string. The function is passed two parameters; the word number, and the
  319.          source string. If there are insufficient words in the string, a zero is
  320.          returned. For example:
  321.                   MyWord := PosWord(4,'What a stupid idea son!');
  322.  
  323.          Assigns the value 15 to MyWord.
  324.  
  325.  
  326. ExtractWords
  327.  
  328.          ExtractWords(StartWord,NoWords:byte; Str:string):string;
  329.          Returns a substring containing a specified number of words (real words,
  330.          not computer words!) extracted from a source string. The function is
  331.          passed three parameters; the number of the first word to extract, the
  332.          total number of words to extract, and the source string. For example:
  333.  
  334.                   NewString := ExtractWords(5,3,'who the hell says
  335.                                                  censorship is good');
  336.          Assigns the value 'censorship is good' to NewString.
  337.  
  338.  
  339.  
  340. Number Conversions
  341. ValidInt
  342.  
  343.          ValidInt(Str:string):boolean;
  344.          This function returns true if the source string represents a valid
  345.          integer, i.e. contains sensible numbers with no spaces or alpha charac-
  346.          ters. The only passed parameter is the source string. For example:
  347.  
  348.                   OK := ValidInt('23xy45');
  349.          Assigns the value false to OK.
  350.  
  351.  
  352.  
  353. ValidHEXInt
  354.          ValidInt(Str:string):boolean;
  355.  
  356.  
  357.  
  358. 14-8                                                                User's Guide
  359. --------------------------------------------------------------------------------
  360.  
  361.          This function returns true if the source string represents a valid HEX
  362.          notation integer, i.e. contains the numbers 0 through 9, or letters 'A"
  363.          through 'F' with no spaces. The only passed parameter is the source
  364.          string. For example:
  365.  
  366.                   OK := ValidHEXInt('2E4A');
  367.          Assigns the value true to OK.
  368.  
  369.  
  370.  
  371. ValidReal
  372.          ValidReal(Str:string):boolean;
  373.  
  374.          This function returns true if the source string represents a valid real
  375.          number, i.e. contains numbers with no spaces or alpha characters. The
  376.          only passed parameter is the source string. For example:
  377.                   OK := ValidReal('89.95');
  378.  
  379.          Assigns the value true to OK.
  380.  
  381.  
  382. StrtoInt
  383.  
  384.          StrToInt(Str:string):integer;
  385.          Converts a number string and returns an integer. If the string is not a
  386.          valid integer, a zero is returned. The function ValidInt can be used to
  387.          check that the string is convertible. For example:
  388.  
  389.                   Salary := StrToInt('30000');
  390.          Assigns the value 30000 to Salary.
  391.  
  392.  
  393.  
  394. StrtoLong
  395.          StrToLong(Str:string):longint;
  396.  
  397.          Converts a number string and returns a longint. If the string is not a
  398.          valid integer, a zero is returned. For example:
  399.                   GoodSalary := StrToLong('300000');
  400.  
  401.          Assigns the value 300000 to GoodSalary.
  402.  
  403.  
  404. StrToReal
  405.  
  406.          StrToReal(Str:string):extended;
  407.  
  408.  
  409. String Handling                                                             14-9
  410. --------------------------------------------------------------------------------
  411.  
  412.          Converts a number string and returns a real. If the string is not a
  413.          valid real, a zero is returned. The function ValidReal can be used to
  414.          determine whether the string is convertible. For example:
  415.  
  416.                   Taxes := StrToReal('15643.27');
  417.          Assigns the value 15643.27 to Taxes.
  418.  
  419.  
  420.  
  421. HEXStrToLong
  422.          HEXStrToLong(Str:string):longint;
  423.  
  424.          Converts a hexadecimal string and returns a longint. If the string is
  425.          not a valid hex number, a zero is returned. The function ValidHEXInt
  426.          can be used to determine whether the string is convertible. For exam-
  427.          ple:
  428.                   Val := HEXStrToLong('FF');
  429.  
  430.          Assigns the value 255 to Val.
  431.  
  432.  
  433. IntToStr
  434.  
  435.          IntToStr(Number:longint):string;
  436.          Returns a number converted to a string. The function is passed one
  437.          parameter; the source number of type byte, word, shortint, integer or
  438.          longint. For example:
  439.  
  440.                   NumStr := IntToStr(365);
  441.          Assigns the value '365' to NumStr.
  442.  
  443.  
  444.  
  445. RealToStr
  446.          RealToStr(Number:extended; Decimals:byte):string;
  447.  
  448.          Returns a real number converted to a string. The function is passed two
  449.          parameters; the source real number, and the number of decimal places.
  450.          If the number of decimal places is passed as FLOATING (a constant), the
  451.          function will return only the significant digits. For example:
  452.                   MeatPie := RealToStr(3.546000,FLOATING);
  453.  
  454.          Assigns the value '3.546' to MeatPie.
  455.  
  456. IntToHEXStr
  457.  
  458.          IntToHEXStr(Number:longint):string;
  459.  
  460. 14-10                                                               User's Guide
  461. --------------------------------------------------------------------------------
  462.  
  463.          Returns a hexadecimal string representing the value of a number. The
  464.          function is passed one parameter; the source number, and it may be of
  465.          type byte, word, shortint, integer or longint. For example:
  466.  
  467.                   SillyPower := IntToHexStr(255);
  468.          Assigns the value 'FF' to SillyPower.
  469.  
  470.  
  471.  
  472. RealtoSciStr
  473.          RealToSciStr(Number:extended; D:byte):string;
  474.  
  475.          Returns a real number converted to a scientific notation string. The
  476.          function is passed two parameters; the source real number, and the
  477.          number of decimal places. For example:
  478.                   Velocity := RealToSciStr(45678.984564,8);
  479.  
  480.          Assigns the value '4.56789846E+04' to Velocity.
  481.  
  482.  
  483. NthNumber
  484.  
  485.          NthNumber(Str:string; Nth:byte):char;
  486.          This function is actually used internally by the Toolkit in the totDATE
  487.          unit, but can be used if you can think of a reason! This function
  488.          returns the character representing a number found in the string. The
  489.          function is passed two parameters; the source string, and a byte indi-
  490.          cating the position of the number to be returned. For example:
  491.  
  492.                   NumChar := NthNumber('02/20/48',5);
  493.          Assigns the value '4' to NumChar.
  494.  
  495.  
  496.  
  497. Examples
  498.          Listed below are the demo programs DEMST1.PAS and DEMST2.PAS, which
  499.          illustrate how to use the string functions. Following each listing is a
  500.          figure detailing the resultant output.
  501.  
  502.          program DemoStringOne;
  503.          {demST1 - string functions}
  504.          Uses DOS, CRT,
  505.               totFAST, totSTR;
  506.  
  507.          Var
  508.             DemoStr : string;
  509.  
  510.  
  511.  
  512. String Handling                                                            14-11
  513. --------------------------------------------------------------------------------
  514.  
  515.          begin
  516.             ClrScr;
  517.             with Screen do
  518.             begin
  519.                DemoStr := '  TechnoJock''s Object Toolkit string demo   ';
  520.                WriteAt(5,1,lightgray,'Source String: ');
  521.                WriteAt(30,1,lightcyan,'"'+DemoStr+'"');
  522.                WriteAt(1,4,lightgray,'SetUpper:');
  523.                WriteAt(30,4,yellow,'"'+SetUpper(DemoStr)+'"');
  524.                WriteAt(1,5,lightgray,'SetLower:');
  525.                WriteAt(30,5,yellow,'"'+SetLower(DemoStr)+'"');
  526.                WriteAt(1,6,lightgray,'SetProper:');
  527.                WriteAt(30,6,yellow,'"'+SetProper(DemoStr)+'"');
  528.                WriteAt(1,7,lightgray,'Total words:');
  529.                WriteAt(30,7,lightgreen,IntToStr(WordCnt(DemoStr)));
  530.                WriteAt(1,8,lightgray,'Posn. Word 3:');
  531.                WriteAt(30,8,lightgreen,IntToStr(PosWord(3,DemoStr)));
  532.                WriteAt(1,9,lightgray,'Words 2..5 are:');
  533.                WriteAt(30,9,yellow,'"'+ExtractWords(2,4,DemoStr)+'"');
  534.                WriteAt(1,10,lightgray,'Strip Leading spaces:');
  535.                WriteAt(30,10,yellow,'"'+Strip('L',' ',DemoStr)+'"');
  536.                WriteAt(1,11,lightgray,'Strip Trailing spaces:');
  537.                WriteAt(30,11,yellow,'"'+Strip('R',' ',DemoStr)+'"');
  538.                WriteAt(1,12,lightgray,'Strip Lng. & Tng. spaces:');
  539.                WriteAt(30,12,yellow,'"'+Strip('B',' ',DemoStr)+'"');
  540.                WriteAt(1,13,lightgray,'Strip All spaces:');
  541.                WriteAt(30,13,yellow,'"'+Strip('A',' ',DemoStr)+'"');
  542.             end;
  543.             GotoXY(1,23);
  544.          end.
  545.  
  546.  
  547. Figure 14.1                                                             [SCREEN]
  548. String
  549. Functions
  550.  
  551.  
  552.          program DemoStringTwo;
  553.          {demST2 - more string functions}
  554.          Uses DOS, CRT,
  555.               totSTR;
  556.  
  557.          Const
  558.              MyInt:integer = 4000;
  559.              MyReal:real = 89.99;
  560.              MyIntStr = '8000';
  561.              MyRealStr = '89.95';
  562.              MyHexStr = 'FFFF';
  563.  
  564.  
  565.  
  566. 14-12                                                               User's Guide
  567. --------------------------------------------------------------------------------
  568.  
  569.          begin
  570.             ClrScr;
  571.             writeln('Test number - ',MyInt);
  572.             writeln;
  573.             writeln('IntToStr:    ',IntToStr(MyInt));
  574.             writeln('IntToHEXStr: ',IntToHEXStr(MyInt));
  575.             writeln;
  576.             writeln;
  577.             writeln('Test number - ',MyReal:5:2);
  578.             writeln;
  579.             writeln('RealToStr: ',RealToStr(MyReal,5));
  580.             writeln('RealToStr: ',RealToStr(MyReal,1));
  581.             writeln('RealToStr: ',RealToStr(MyReal,FLOATING));
  582.             writeln('RealToSciStr: ',RealToSciStr(MyReal,FLOATING));
  583.             writeln;
  584.             writeln;
  585.             writeln('Test Strings: ',MyIntStr,' ',MyRealStr,' ',MyHEXStr);
  586.             writeln;
  587.             writeln('ValidInt: ',ValidInt(MyIntStr));
  588.             writeln('ValidInt: ',ValidInt(MyHEXStr));
  589.             writeln('ValidInt: ',ValidInt(MyRealStr));
  590.             writeln('ValidReal: ',ValidReal(MyIntStr));
  591.             writeln('ValidReal: ',ValidReal(MyRealStr));
  592.             GotoXY(1,23);
  593.          end.
  594.  
  595.  
  596.  
  597. Figure 14.2                                                             [SCREEN]
  598. More String
  599. Functions
  600.  
  601.  
  602.  
  603. FmtNumberOBJ
  604.          The totSTR unit includes the object FmtNumberOBJ. This object includes
  605.          function methods which accept numbers, and return them as formatted
  606.          strings. The object is used to provide formatting capabilities to the
  607.          number input fields in the totIO units (see page 11-21), but it may
  608.          also be used independently to provide sophisticated number formatting
  609.          control.
  610.  
  611.          The object can format both integer and real numbers, and the format
  612.          options include the following:
  613.          Prefix     The number can be preceded by a character or short string,
  614.                     e.g. '$'.
  615.  
  616.          Suffix     The number can be succeeded by a character or short string,
  617.                     e.g. 'FFr'
  618.  
  619.  
  620. String Handling                                                            14-13
  621.  
  622. --------------------------------------------------------------------------------
  623.  
  624.          Sign       The number can be signed with + and/or -, parentheses on
  625.                     negative numbers, or DB/CR to indicate debit and credit.
  626.  
  627.          Separators The number can have thousands separated by a character, e.g.
  628.                     ','. Even the decimal place character and the character used
  629.                     to pad the string can be specified.
  630.          Justificat The number can be left, right or center justified in the
  631.          ion        allotted space.
  632.  
  633.  
  634.          To format numbers, you must initialize an instance of type FormatNum-
  635.          berOBJ, specify the appropriate format options, and call a function
  636.          method to return the number formatted as a string. The following
  637.          methods are available:
  638.  
  639.  
  640.          Init;
  641.          This method initializes the object and must be called before the other
  642.          methods.
  643.  
  644.  
  645.          SetPrefixSuffix(P,S:string);
  646.          Specifies the strings that will be used to precede and succeed the
  647.          number. Pass a null string, i.e. '', to suppress either the prefix or
  648.          suffix.
  649.  
  650.  
  651.          SetSign(S:tSign);
  652.          The totSTR unit includes the declaration of an enumerated type tSign
  653.          with the following members: PlusMinus, Minus, Brackets, DbCr
  654.  
  655.          PlusMinus  Always precedes the number with a '+' or '-' to indicate the
  656.                     sign of the number.
  657.          Minus      Only displays a '-', i.e. if the number is positive, the '+'
  658.                     is not displayed.
  659.  
  660.          Brackets   Negative numbers are enclosed in parentheses, e.g. (25.67).
  661.          DbCr       If the number is negative it is succeeded with the string
  662.                     'DB', otherwise it is succeeded with the string 'CR'.
  663.  
  664.          Use this method to specify how the sign of a number will be displayed.
  665.  
  666.          SetSeparators(P,T,D:char);
  667.  
  668.          Three different separators may be required to format a number, and this
  669.          method identifies them. The first parameter is the character used to
  670.          pad the string to the specified width, and common values are ' ' or
  671.          '*'. The second parameter specifies the character used to separate each
  672.  
  673. 14-14                                                               User's Guide
  674. --------------------------------------------------------------------------------
  675.  
  676.          significant thousand, and typically has a value of ','. Specify #0, if
  677.          you don't want a thousands separator. The last parameter specifies the
  678.          character indicating the decimal place, e.g. '.'.
  679.  
  680.  
  681.          SetJustification(J:tJust);
  682.          When the number is formatted, it can be left, center, or right justi-
  683.          fied. Pass a value of JustLeft, JustCenter or JustRight to identify the
  684.          required justification.
  685.  
  686.  
  687.          FormattedLong(Val:longint;Width:byte):string;
  688.          Having set all the formatting options as required, call this method to
  689.          return a formatted string. The method is passed two parameters; any
  690.          whole number (i.e. byte, word, shortint, integer, longint), and the
  691.          width of the string. If the formatted string is too long to fit in the
  692.          specified width, an unformatted string is returned.
  693.  
  694.  
  695.          FormattedReal(Val:extended;DP,Width:byte):string;
  696.          This function method is similar to the method FormattedLong, except it
  697.          is used to format real numbers. The method is passed three parameters;
  698.          the real number, the number of decimal places, and the width of the
  699.          returned string. The TotSTR unit includes a global constant FLOATING.
  700.          When FLOATING is specified as the number of decimal places, the Toolkit
  701.          will show all decimal places up to the last non-zero decimal.
  702.  
  703.  
  704.          Done
  705.          This method disposes of the memory used by the instance, and should be
  706.          called when the object is no longer required.
  707.  
  708.  
  709.  
  710.            Note: the totIO2 unit includes a global instance FmtNumberTOT
  711.            which is used to specify the default format for number input
  712.            fields. Refer to page 11-22 for further details.
  713.  
  714.  
  715.  
  716.          Listed below is the demo program DEMST3.PAS, which illustrates how to
  717.          use FmtNumberOBJ objects.
  718.  
  719.          program DemoStringThree;
  720.          {demST3 - number formatting}
  721.          Uses DOS, CRT,
  722.               totFAST, totSTR;
  723.  
  724.  
  725.  
  726. String Handling                                                            14-15
  727. --------------------------------------------------------------------------------
  728.  
  729.          Var
  730.             Fmt: FmtNumberOBJ;
  731.  
  732.          begin
  733.             ClrScr;
  734.             with Fmt do
  735.             begin
  736.                Init;
  737.                writeln(FormattedLong(2000,15));
  738.                writeln(FormattedReal(2000,2,15));
  739.                SetSign(PlusMinus);
  740.                writeln(FormattedLong(2000,15));
  741.                SetSign(DBCR);
  742.                writeln(FormattedReal(2000,3,15));
  743.                SetPrefixSuffix('$','');
  744.                writeln(FormattedReal(2000,3,15));
  745.                SetSeparators('*',',','.');
  746.                writeln(FormattedReal(2000,3,15));
  747.                SetJustification(JustRight);
  748.                writeln(FormattedReal(2000,3,15));
  749.                Done;
  750.             end;
  751.             GotoXY(1,23);
  752.          end.
  753.  
  754. Figure 14.3                                                             [SCREEN]
  755. Formatting
  756. Numbers
  757.